package days29.Title141;

import java.util.HashSet;
import java.util.Set;

/**
 * @Author fengzihao
 * @Date 2024-05-13 21:02
 */
public class Title141 {
}
/*
*
Definition for singly-linked list.
class ListNode {
    int val;
    ListNode next;
     ListNode(int x) {
        val = x;
        next = null;
   }
}
*/
// Definition for singly-linked list.
class ListNode {
    int val;
    ListNode next;
    ListNode(int x) {
        val = x;
        next = null;
    }
}
class Solution {
    public boolean hasCycle(ListNode head) {
        Set<ListNode> seen = new HashSet<ListNode>();
        while (head != null) {
            if (!seen.add(head)) {
                return true;
            }
            head = head.next;
        }
        return false;
    }
}